//- Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd. 
//- <https://www.chatopera.com>, Licensed under the Chunsong Public 
//- License, Version 1.0  (the "License"), https://docs.cskefu.com/licenses/v1.html
//- Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
//- Copyright (C) 2018-Jun. 2023 Chatopera Inc, <https://www.chatopera.com>
//- Licensed under the Apache License, Version 2.0
//- http://www.apache.org/licenses/LICENSE-2.0
extends /admin/include/layout.pug

mixin operations(dictid, dictname, pageNumber)
    td(style="white-space:nowrap;" nowrap="nowrap")
        a(href="/admin/sysdic/dicitem/edit.html?id=" + dictid + "p=" + pageNumber,data-width="550", data-height="450", data-toggle="ajax",  title="编辑" + dictname)
            i.layui-icon &#xe642;
            span 编辑
        a(href="/admin/sysdic/dicitem/delete.html?id=" + dictid + "&p=" + pageNumber, data-toggle="tip" data-title="删除字典项同时会删除字典项下的所有子项，请确认是否删除字典项“" + dictname + "”？", title="删除" + dictname)
            i.layui-icon(style="color:red;") &#x1006;
            span 删除

block content
    .row
        .col-lg-12
            h1.site-h1(style='background-color:#FFFFFF;')
                | #{sysDic.name} 字典项 (#{sysDicList.totalElements})
                span(style='float:right;')
                    button.layui-btn.layui-btn-small.green(href='/admin/sysdic/dicitem/add.html?id=' + sysDic.id, data-toggle='ajax', data-width='550', data-height='450', data-title='创建新字典项')
                        | 创建新字典项
                    button.layui-btn.layui-btn-small.green(href='/admin/sysdic/dicitem/batadd.html?id=' + sysDic.id, data-toggle='ajax', data-width='750', data-title='创建新字典项')
                        | 批量创建字典项
            .row(style='padding:5px;')
                .col-lg-12
                    table.layui-table(lay-skin='line')
                        colgroup
                            col(width='20%')
                            col(width='10%')
                            col(width='10%')
                            col(width='10%')
                            col(width='35%')
                            col(width='10%')
                            col
                        if sysDic.ctype == "auth"
                            thead
                                tr
                                    th 名称
                                    th 代码
                                    th URL
                                    th 菜单级别
                                    th 样式
                                    th(style="white-space:nowrap;" nowrap="nowrap") 操作
                            tbody
                                if size(sysDicList.content) > 0
                                    for dic in sysDicList.content
                                        tr
                                            td: a(href="/admin/sysdic/dicitem.html?id=" + dic.id + "&dicid=" + dic.id) dic.name
                                            td= dic.code
                                            td= dic.url
                                            if dic.level == "1"
                                                td 一级菜单
                                            else if dic.level == "2"
                                                td 二级菜单
                                            else if dic.level == "3"
                                                td 三级菜单
                                            else if dic.level == "4"
                                                td 按钮或链接
                                            td= dic.iconstr
                                            +operations(dic.id, dic.name, sysDicList.number + 1)
                        else
                            thead
                                tr
                                    th 名称
                                    th 代码
                                    th 图标
                                    th 显示代码
                                    th 创建时间
                                    th(style="white-space:nowrap;" nowrap="nowrap") 操作
                            tbody
                                if size(sysDicList.content) > 0
                                    for dic in sysDicList.content
                                        tr
                                            td: a(href="/admin/sysdic/dicitem.html?id=" + dic.id + "&dicid=" + dic.id)= dic.name
                                            td= dic.code
                                            if dic.iconskin
                                                small(class="ukefu-label" style="background-color:" + dic.iconskin + ";")
                                                    if dic.iconstr
                                                        i(class=dic.ctype)!= dic.iconstr
                                                    | #{dic.name}
                                            else
                                                td
                                            if dic.discode
                                                td: i.layui-icon(style="color:#19a55d;") &#xe618;
                                            else
                                                td
                                            if dic.createtime
                                                td= pugHelper.formatDate('yyyy-MM-dd HH:mm:ss', dic.createtime)
                                            else
                                                td
                                            +operations(dic.id, dic.name, sysDicList.number + 1)


            .row(style='padding:5px;')
                .col-lg-12#page(style='text-align:center;')
    script.
        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage
                , layer = layui.layer;
            var msg = "#{msg}"
            if (msg) top.layer.msg(msg);
            laypage({
                cont: 'page'
                , pages: #{sysDicList.totalPages} //总页数
                , curr: #{sysDicList.number + 1}
                , groups: 5 //连续显示分页数
                , jump: function (data, first) {
                    if (!first) {
                        location.href = "/admin/sysdic/dicitem.html?id=#{sysDic.id}&p=" + data.curr;
                    }
                }
            });
        });

